<?php
if(JRequest::getVar('showtime', '0')!='0')
	$time=JRequest::getVar('showtime','0');
else
	$time=time();

$today = getdate($time); 
$mday = $today ['mday'];
$mon  = $today ['mon'];   
$year  = $today ['year'];  

$time = mktime(0, 0, 0, $mon,1,$year);

$today = getdate($time); 
$wday  = $today ['wday'];  
$year  = $today ['year'];  
$weekday = $today ['weekday'];
$month  = $today ['month'];
$i= -$wday;
$thisPage=$_SERVER['PHP_SELF'];

$time = mktime(0, 0, 0, $mon+1,0,$year);
$lastDay=date('j',$time);
?>
<div class="box_ydelser m10t">
  <p class="p10l p5t p5b"><span class="style2">VAGTPLAN</span></p>
  <div class="tt_calenda">
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
      <tbody>
        <tr>
          <td height="23" align="center" width="13%"><a href='index.php?option=com_content&view=article&layout=profil&id=8&Itemid=2&showtime=<?php echo mktime(0, 0, 0, $mon-1,$mday,$year); ?>' title='Previous Month' class='event_link'><img src="/templates/xescort/images/icon_left.png"></a></td>
          <td align="center" width="72%"><?php echo $month;?> - <?php echo $year; ?></td>
          <td align="center" width="15%"><a href='index.php?option=com_content&view=article&layout=profil&id=8&Itemid=2&showtime=<?php echo mktime(0, 0, 0, $mon+1,$mday,$year); ?>' title='Next Month' class='event_link'><img src="/templates/xescort/images/icon_right.png"></a></td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="bg_ydelser p5t p5b">
    <table cellspacing="0" cellpadding="0" border="0" align="center" width="100%">
      <tbody>
        <tr>
          <td align="center" class="style2 border2_bt p4">S</td>
          <td align="center" class="style2 border2_bt p4">M</td>
          <td align="center" class="style2 border2_bt p4">T</td>
          <td align="center" class="style2 border2_bt p4">W</td>
          <td align="center" class="style2 border2_bt p4">T</td>
          <td align="center" class="style2 border2_bt p4">F</td>
          <td align="center" class="style2 border2_bt p4">S</td>
        </tr>
        <?php
			for($j=0;$j<6;$j++){ 
		?>
        <tr>
        <?php	
				for($k=0;$k<7;$k++){ 
					$i++;			
		?>
		<td align='center' width='12%' height='25'>
		<?php
					if(array_key_exists($i,$events)){
		?>
        				<a href=""><?php echo ($i>0&&$i<=$lastDay)?$i:''; ?></a>
        <?php				
					}else{
						echo ($i>0&&$i<=$lastDay)?$i:'';
					}
		?>
		</td>
        <?php
				}
		?>
        </tr>
        <?php
				
			}
		?>
      </tbody>
    </table>
  </div>
</div>
